package com.ujiuye.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * 监听session作用域值的变化
 */
//@WebListener
public class Demo02Listener implements HttpSessionAttributeListener {


    //添加
    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        System.out.println("session添加键值对");
        String name = se.getName();
        Object value = se.getValue();
        System.out.println(name + "..." + value);
    }


    //移除
    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        System.out.println("session移除键值对");
        String name = se.getName();
        Object value = se.getValue();
        System.out.println(name + "..." + value);
    }

    //替换
    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        System.out.println("session替换键值对");
        String name = se.getName();
        Object value = se.getValue();
        System.out.println(name + "..." + value);
    }
}
